package com.xinghou.platform.dao.mange.impl;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
import javax.annotation.Resource;
import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Repository;
import com.xinghou.platform.dao.bases.JdbcTemplate;
import com.xinghou.platform.dao.bases.database.CustomerContextHolder;
import com.xinghou.platform.dao.mange.AttachmentDAO;


/**
 * 
 * @author wlw
 * 
 */
@Repository
public class AttachmentDAOImpl implements AttachmentDAO {
	@Resource
	private JdbcTemplate jdbcTemplate;

	@Override
	public List<String> getAttachmentById(Integer attachId)throws DataAccessException {
		CustomerContextHolder.setCustomerType(CustomerContextHolder.DATA_SOURCE_READ);
		String sql="SELECT 	File_uri FROM attachment a WHERE a.Attach_id=?";
		List<String> fileUri = jdbcTemplate.query(sql, new Object[] {attachId}, new StringMapper());
		CustomerContextHolder.clearCustomerType();
		return fileUri;
	}
	
	private static final class StringMapper implements RowMapper<String> {
		public String mapRow(ResultSet rs, int rowNum) throws SQLException {
			return rs.getString(1);
		}
	}

	
}
